package com.danger.dy.blogger;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.danger.dy.common.models.exceptions.LogicException;
import com.danger.dy.common.models.response.AnyObject;
import com.danger.dy.common.models.response.AnyResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * AnyController
 */
@RestController
@RequestMapping("/api/any")
public class AnyController {

    @GetMapping("/test")
    public AnyResponse<AnyObject> test(@RequestParam(name = "want") String want) {
        if (want.equals("500")) {
            throw new RuntimeException("who's your daddy");
        } else if (want.equals("406")) {
            throw new LogicException(406, "greed is good");
        } else if (want.equals("error_response")) {
            return AnyResponse.error(406, "the mountain is high");
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            return AnyResponse.ok(AnyObject.of(sdf.format(new Date())));
        }
    }
}
